import { QueryOptionsDto } from 'src/dto/query.options.dto';
import { ApiProperty } from '@nestjs/swagger';
import { ValidateIf, IsOptional, IsEnum, IsString } from 'class-validator';
import { Type } from 'class-transformer';

export class RoleListDto extends QueryOptionsDto {
    @ApiProperty({ required: true, description: '角色名称' })
    @IsString({ message: '用户名必须为字符类型' })
    @ValidateIf((o) => o.rolename != '')
    @IsOptional()
    readonly rolename: string;
  
    @ApiProperty({ required: true, description: '角色说明' })
    @IsString({ message: '角色说明必须为字符类型' })
    @ValidateIf((o) => o.description != '')
    @IsOptional()
    readonly description: string;
  
    @ApiProperty({ required: false, description: '是否为默认角色', enum: [0, 1] })
    @IsEnum({ 否: 0, 是: 1 }, { message: '默认角色必须是(0:表示否,1:表示是)的数字' })
    @Type(() => Number)//把获取到的值转化为number
    @ValidateIf((o) => o.isDefault != '')
    @IsOptional()
    readonly isDefault?: number;
}
